export default {
	data(){
		return{
			screenWidth:"",
			screenHeight:''
		}
	},
	async drawImage() {
		// if (!uni.getStorageSync('userInfo')) {
		// 	uni.navigateTo({
		// 		url: "../register/wechatRegister"
		// 	})
		// 	return
		// }

		// await this.getCode()

		uni.showLoading({
			title: "海报绘制中~"
		})
		 uni.getSystemInfo({
			success:res=> {
				  let windowWidth=res.windowWidth;
				  let windowHeight=res.windowHeight;
				  this.screenWidth=windowWidth;
				  this.screenHeight=windowHeight;
				  console.log(res)
			}
		})
		this.$nextTick(async () => {
			
			// 初始化
			await this.$refs.rCanvas.init({
				canvas_id: "rCanvas"
			})
			this.$refs.rCanvas.show = true
			// 画图
			await this.$refs.rCanvas.drawImage({
				url: this.info.cover,
				x: 0,
				y: 0,
				w: this.screenWidth *0.8,
				h: this.screenHeight*0.8
			}).catch(err_msg => {
				uni.showToast({
					title: err_msg,
					icon: "none"
				})
			})
			// 画标题
			await this.$refs.rCanvas.drawText({
				text: this.info.title,
				max_width: 300,
				line_clamp: 2,
				x: 12,
				y: 270,
				font_color: "rgb(67, 66, 67)",
				font_size: 16,
				font_weight: "bolder"
			}).catch(err_msg => {
				uni.showToast({
					title: err_msg,
					icon: "none"
				})
			})

			// 画价格
			await this.$refs.rCanvas.drawText({
				text: '￥' + this.info.price,
				x: 8,
				y: 320,
				font_color: "rgb(243, 52, 14)",
				font_size: 22,

			}).catch(err_msg => {
				uni.showToast({
					title: err_msg,
					icon: "none"
				})
			})

			// 画旧价格
			await this.$refs.rCanvas.drawText({
				text: '￥' + this.info.oldprice,
				x: 12,
				y: 340,
				font_color: "rgb(177, 179, 177)",
				font_size: 14,
				line_through_height: "1",
				line_through_color: "rgb(177, 179, 177)"
			}).catch(err_msg => {
				uni.showToast({
					title: err_msg,
					icon: "none"
				})
			})



			// 画头像
			await this.$refs.rCanvas.drawImage({
				url: uni.getStorageSync("userInfo").avatar,
				x: 10,
				y: 400,
				w: 40,
				h: 40,
				circle: true
			}).catch(err_msg => {
				uni.showToast({
					title: err_msg,
					icon: "none"
				})
			})


			// 画名字
			await this.$refs.rCanvas.drawText({
				text: "长按二维码保存",
				x: 55,
				y: 435,
				font_color: "rgb(48, 48, 48)",
				font_size: 14,

			}).catch(err_msg => {
				uni.showToast({
					title: err_msg,
					icon: "none"
				})
			})



			// 画qr
			await this.$refs.rCanvas.drawImage({
				url: this.qr,
				x: 200,
				y: 380,
				w: 80,
				h: 80,
				circle: true
			}).catch(err_msg => {
				uni.showToast({
					title: err_msg,
					icon: "none"
				})
			})



			// 生成海报
			await this.$refs.rCanvas.draw((res) => {
				this.image = res.tempFilePath
				uni.hideLoading()
				//res.tempFilePath：生成成功，返回base64图片
			})
		})
	}
}


